﻿var uid = uid || "";
var countdown=60; //60秒超时
$(function(){
	$(window).scroll(function() {      
        if($(window).scrollTop() >= 100){
            $('#top').fadeIn(300); 
        }else{    
            $('#top').fadeOut(300);    
        }  
    });
    $('#top').click(function(){
    $('html,body').animate({scrollTop: '0px'}, 600);});   
    switchLogin();
    showAndHideUserCard();
    //hideExperienceMember();
});	
//初始化Banner
function initIndexBanner() {
	$('#banner-index').flexslider({
		animation: "slide",
		direction:"horizontal",
		easing:"swing",
		slideshowSpeed: 5000
	});
}

// 初始化分享
function initShare() {
    window._bd_share_config = {
        "common": {
            "bdSnsKey": {},
            "bdText": "",
            "bdMini": "2",
            "bdPic": "",
            "bdStyle": "0",
            "bdSize": "16"
        },
        "share": {},
        "image": {"viewList": ["qzone", "tsina", "tqq", "renren", "weixin"], "viewText": "分享到：", "viewSize": "16"},
        "selectShare": {"bdContainerClass": null, "bdSelectMiniList": ["qzone", "tsina", "tqq", "renren", "weixin"]}
    };
    with (document)0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];
}

// 导航样式选中
function navClassSelect (target, id, active) {
	var objList = $(target);
	for(var i = 0; i < objList.length; i++ ){
		$(objList[i]).prop("class","");
	}
	$("#"+id).prop("class", active);
}

// 登录切换
function switchLogin() {
	$(".login-content").first().show();
	$(".tab li").click(function(){
		var z = $(this).index();
		$(this).addClass("cur").siblings().removeClass("cur");
		$(".login-content").eq(z).show().siblings(".login-content").hide();
		$("#login-tips").text("");
		$("#login-tab .input-wrapper input").val("");
		if (z === 0) {
			changeVcode('login-vcode');
		}
		if (z === 1) {
			bindVcode('sh-login-vcode');
			changeVcode('sh-login-vcode');
		}
	})
}
//显示遮罩层和弹窗
function defaultLetDivCenter(showClass, model){  
	$(".error-tips").text("");
	$(".input-wrapper input:not(.countdown)").val("");
 	$(".popup-mask").css({
		"display": "block", "height": $(document).height()
	});
	var $box = $(showClass);
	$box.css({
		"left": ($("body").width() - $box.width()) / 2 + "px",
		"top": ($(window).height() - $box.height()) / 2 + $(window).scrollTop() + "px",
		"display": "block"
	});
	if (model != undefined) {
		bindVcode(model+'-vcode');
		changeVcode(model+'-vcode');
	}
}  

// 显示遮罩层和弹窗
function letDivCenter(showClass, hideClass, model){ 
	if (hideClass != undefined) {
		letDivHide(hideClass);
	}
	defaultLetDivCenter(showClass, model);
}  

// 隐藏遮罩层和弹窗
function letDivHide(hideClass) {
	$(hideClass).hide();
	$(".popup-mask").hide();
	if(hideClass == ".login-model-popup"){
	 	window.location.reload();
	}
}

// 关闭layer弹层
function closeLayer(){
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}

// 判断用户是否登录
function isLogin() {
	var flage = false;
	$.ajax({
		async:false,
		type:"POST",
		url:"/user/islogin",
		dataType:"json",
		success:function(data){
			if(data.code === "100"){
				flage = true;
				return;
			}
			letDivCenter('.login-model');
			return;
		}
	});
	return flage;
}

// 用户登录（普通登录）
function userLogin(){
	var username = $.trim($("#login-account").val());
	var password = $.trim($("#login-password").val());
	var vcode = $.trim($("#login-vcode").val());
	if ("" == username || typeof (username) == undefined) {
		$("#login-tips").text("请输入正确的用户名或手机号或邮箱！");
		changeVcode("login-vcode");
		return;
	}
	if ("" == password || typeof (password) == undefined) {
		$("#login-tips").text("请输入密码，区分大小写，不能用空格！");
		return;
	}
	// if ("" == vcode || typeof (vcode) == undefined) {
	// 	$("#login-tips").text("请输入图形验证码！");
	// 	return;
	// }
	var data = {
		username: username,
		password: password,
		// vcode: vcode,
		// loginMethod: '00'
	};
	$.ajax({
		type : "POST",
		url : "/check_login",
		data : data,
		dataType : "json",
		beforeSend:function(){
			buttonStatus(0,'login','正在登录');
		},
		success : function(data) {
			if (data.code == "100") {
				showUserInfo(1);
				letDivHide('.login-model-popup');
			} else {
				$("#login-tips").text(data.mesg);
				changeVcode("login-vcode");//重新加载图形验证码
				buttonStatus(1,'login','立即登录');
			}
		},
		complete: function () {
			isAvailableCoupon();
	    },
		error : function() {
			$("#login-tips").text("网络异常,请稍候再试！");
			buttonStatus(1,'login','正在登录');
		}
	});
}

//用户登录（税号登录）
function shuihaoLogin(){
	var username = $.trim($("#sh-login-account").val());
	var password = $.trim($("#sh-login-password").val());
	var vcode = $.trim($("#sh-login-vcode").val());
	if ("" == username || typeof (username) == undefined) {
		$("#login-tips").text("请输入税号！");
		changeVcode("login-vcode");
		return;
	}
	if ("" == password || typeof (password) == undefined) {
		$("#login-tips").text("请输入密码，区分大小写！");
		return;
	}
	if ("" == vcode || typeof (vcode) == undefined) {
		$("#login-tips").text("请输入图形验证码！");
		return;
	}
	var data = {
		username: username,
		password: password,
		vcode: vcode,
		loginMethod: '01'
	}
	$.ajax({
		type : "POST",
		url : "/check_login",
		data : data,
		dataType : "json",
		beforeSend:function(){
			buttonStatus(0,'login','正在登录');
		},
		success : function(data) {
			if (data.code == "100") {
				showUserInfo(1);
				letDivHide('.login-model-popup');
			} else {
				$("#login-tips").text(data.mesg);
				changeVcode("sh-login-vcode");
				buttonStatus(1,'login','立即登录');
			}
		},
		complete: function () {
			isAvailableCoupon();
	    },
		error : function() {
			$("#login-tips").text("网络异常,请稍候再试！");
			changeVcode("sh-login-vcode");
			buttonStatus(1,'login','正在登录');
			layer.close(layer.tips());
		}

	});
}

// 用户注册
function userRegister(){
	var username = $.trim($("#register-account").val()); //用户名
	var password = $.trim($("#register-password").val()); //密码
	var vcode = $.trim($("#register-vcode").val()); //图形验证码
	var mcode = $.trim($("#register-mcode").val()); //手机验证码
	var protocol = $("input[type='checkbox']").is(':checked')	
	var patrn = /^[0-9]{1,20}$/;
	if (username == "") {
		$("#register-tips").text("请输入注册的手机号！");
		return;
	}
	if (!patrn.exec(username)){
		$("#register-tips").text("请输入正确的手机号！");
		return;
	}
	if (mcode == "") {
		$("#register-tips").text("请输入手机验证码！");
		return;
	}
	if (password == "") {
		$("#register-tips").text("请输入密码[至少6位]");
		return;
	}
	if (password.length < 6) {
		$("#register-tips").text("密码不能少于6位！");
		return;
	}
	if (vcode == "") {
		$("#register-tips").text("请输入图形验证码！");
		return;
	}
	if (mcode == "") {
		$("#register-tips").text("请输入手机验证码！");
		return;
	}
	if(!protocol){
		$("#register-tips").text("请选择注册服务协议！");
		return;
	}
	var data = {
		username: username,
		password: password,
		vcode: vcode,
		mcode: mcode
	}
	var loads;
	$.ajax({
		type : "POST",
		url : "/register/information/save",
		data : data,
		dataType : "json",
		beforeSend:function(){
			buttonStatus(0,'register','正在注册');
		},
		success : function(data) {
			layer.close(loads);
			if (data.code == "100") {
				letDivCenter('.register-suc-model','.register-model')
			} else {
				$("#register-tips").text(data.mesg);
				changeVcode("register-vcode");
				buttonStatus(1,'register','注册');
			}
		},
		error : function() {
			$("#register-tips").text("网络异常,请稍候再试！");
			changeVcode("register-vcode");
			buttonStatus(1,'register','正在注册');
		}
	});
}
// 获取注册短信验证码
function getRegisterVcode(obj){
	var mobile = $.trim($("#register-account").val());
	var vcode = $.trim($("#register-vcode").val()); //图形验证码
	var patrn=/^[0-9]{1,20}$/;
	if ("" == mobile || typeof (mobile) == undefined) {
		$("#register-tips").text("请输入手机号！");
		return;
	}
	if (!patrn.exec(mobile)){
		$("#register-tips").text("请输入正确的手机号！");
		return;
	}
	if ("" == vcode || typeof (vcode) == undefined) {
		$("#register-tips").text("请输入图形验证码！");
		return;
	}
	$.ajax({
		type:"post",
		url:"/register/sms/verification/code",
		data:{
			mobile: mobile,
			vcode: vcode
		},
		dataType:"json",
		success: function(data){
			if(data.code=="100"){
				layer.msg("验证码已发送！", {icon: 1,time: 2000},function(){
					settime(obj);
				});
			}else{
				$("#register-tips").text(data.mesg);
				changeVcode("register-vcode");
			}
		},
		error:	function(){
			$("#register-tips").text("网络异常,请稍候再试！");
			changeVcode("register-vcode");
		}
	});	
}

// 获取找回密码短信验证码
function getFindPwdVcode(obj){
	var mobile = $.trim($("#findpwd-account").val());
	var vcode = $.trim($("#findpwd-vcode").val());
	var patrn=/^[0-9]{1,20}$/;
	if ("" == mobile || typeof (mobile) == undefined) {
		$("#findpwd-tips").text("请输入手机号！");
		return;
	}
	if (!patrn.exec(mobile)){
		$("#findpwd-tips").text("请输入正确的手机号！");
		return;
	}
	if ("" == vcode || typeof (vcode) == undefined) {
		$("#findpwd-tips").text("请输入图形验证码！");
		return;
	}
	$.ajax({
		type:"post",
		url:"/find/pwd/sms/verification/code",
		data:{
			mobile: mobile,
			vcode: vcode
		},
		dataType:"json",
		success: function(data){
			if(data.code=="100"){
				layer.msg("验证码已发送！", {icon: 1,time: 3000},function(){
					settime(obj);
				});
			}else{
				$("#findpwd-tips").text(data.mesg);
				//changeVcode("findpwd-vcode");
			}
		},
		error:	function(){
			$("#findpwd-tips").text("网络异常,请稍候再试！");
			changeVcode("findpwd-vcode");
		}
	});	
}

// 验证手机
function verifyPhone(){
	var mobile = $.trim($("#findpwd-account").val());
	var vcode = $.trim($("#findpwd-vcode").val());
	var mcode = $.trim($("#findpwd-mcode").val());
	var patrn = /^[0-9]{1,20}$/;
	if ("" == mobile || typeof (mobile) == undefined) {
		$("#findpwd-tips").text("请输入手机号！");
		return;
	}
	if (!patrn.exec(mobile)){
		$("#findpwd-tips").text("请输入正确的手机号！");
		return;
	}
	if ("" == vcode || typeof (vcode) == undefined) {
		$("#findpwd-tips").text("请输入图形验证码！");
		return;
	}
	if ("" == mcode || typeof (mcode) == undefined) {
		$("#findpwd-tips").text("请输入手机验证码！");
		return;
	}
	var data = {
		mobile: mobile,
		vcode: vcode,
		mcode: mcode
	}
	var loads;
	$.ajax({
		type : "POST",
		url : "/verify/phone/verification/code",
		data : data,
		dataType : "json",
		beforeSend:function(){
			buttonStatus(0,'verify','验证中');
		},
		success : function(data) {
			layer.close(loads);
			if (data.code == "100") {
				uid = data.object;
				letDivCenter('.verify-suc-model', '.findpwd-model');
			} else {
				$("#findpwd-tips").text(data.mesg);
				changeVcode("findpwd-vcode");
				buttonStatus(1,'verify','验证手机');
			}
		},
		error : function() {
			$("#findpwd-tips").text("网络异常,请稍候再试！");
			changeVcode("findpwd-vcode");
			buttonStatus(1,'verify','验证手机');
		}

	});
}

//设置新密码
function setNewPassword(){
	letDivHide('.verify-suc-model');
	window.location.href = "/find/password/step2?uid="+uid;
}

//设置按钮状态
function buttonStatus(type,id,mesg){
	if(type==0){
		$("#"+id).val(mesg);
		$("#"+id).prop("disabled","disabled");	
	}else{
		$("#"+id).val(mesg);
		$("#"+id).removeAttr("disabled");	
	}
}

//为按钮绑定获取图形验证码功能
function bindVcode(id){
	$('#'+id+'_').click(function() {$(this).attr('src','/verify/image?' + Math.floor(Math.random() * 100));});	
}

//更换验证码
function changeVcode(id){
  $('#'+id).val('');
  $('#'+id+'_').attr('src','/verify/image?' + Math.floor(Math.random() * 100)); 
}

//短信验证码倒计时
function settime(obj) {
	if (countdown == 0) { 
		obj.removeAttribute("disabled");    
		obj.value="获取验证码"; 
		countdown = 60; 
		return;
	} else { 
		obj.setAttribute("disabled", true); 
		obj.value="重新获取(" + countdown + ")"; 
		countdown--; 
	} 
	setTimeout(function() { 
		settime(obj) }
		,1000) 
}

function init_placeholder(){
  var doc = document,
  inputs = doc.getElementsByTagName('input'),
  supportPlaceholder = 'placeholder' in doc.createElement('input'),
  placeholder = function(input) {
      var text = input.getAttribute('placeholder'),
      defaultValue = input.defaultValue;
      if (defaultValue == '') {
          input.value = text
      }
      input.onfocus = function() {
          if (input.value === text) {
              this.value = ''
          }
      };
      input.onblur = function() {
          if (input.value === '') {
              this.value = text
          }
      }
  };
  if (!supportPlaceholder) {
      for (var i = 0,
      len = inputs.length; i < len; i++) {
          var input = inputs[i],
          text = input.getAttribute('placeholder');
          if (input.type === 'text' && text) {
              placeholder(input)
          }
      }
  }	
}

//当检索框输入回车键，提交登录信息
document.onkeyup = function (event) {
	var e = event || window.event;
    var keyCode = e.keyCode || e.which;
    if(keyCode ===13){
    	//$("#search-btn").click();
    	siteSearch();
    }
}

// 设置检索内容
function siteSearch(){
	var searchKeywords = $("#searchKeywords").val().trim();
	//var searchType = $("#searchType option:selected").val();
	//var searchTypeText = $("#searchType").find("option:selected").text().trim();
	if(searchKeywords=="" ||searchKeywords==undefined){
		//searchKeywords="财税";
		return;
	}
	searchSiteCentent(searchKeywords);
}

function searchSiteCentent(keywords){
	var type = '00';
	window.location.href = "/search/index/"+type+"?keywords="+keywords;
}
//设置用户信息
function showUserInfo(state) {
	$.ajax({
		async:true,
		type:"POST",
		url:"/load/user/card/info",
		dataType:"json",
		success:function(data){
			if(state !== 1){
				$("#user-box").empty();
			}
			if(data.code == "100"){
				var obj = data.object;
				var courseId = obj.courseId;
				var status = obj.memberStatus;
				var level = obj.memberLevel;
				var memberLevel = "";
				var memberCode = 56;
				var indexRoute = "index";
				var orderRoute = "order/list";
				var courseRoute = "order/curriculum";
				var favoriteRoute = "attention/collection";
				var memberStr = "";
				switch (level) {
				case "HJ1001":
					memberLevel = '黄橘初级会员';
					memberCode = 56;
					break;
				case "HJ1002":
					memberLevel = '黄橘中级会员';
					memberCode = 116;
					break;
				}
				switch (status) {
				case "00":
					memberStr = '<div class="meta"><a href="javascript:;" onclick="openOrRenewMember('+memberCode+');" style="font-size:12px;color:#F29030;">开通会员，名师课程免费看</a><br></div>';
					break;
				case "01":
					memberStr = '<a href="/static/member/hjhy/index.html"" style="margin-left: 4px;"><img src="/images/hj_icon.png" alt="黄橘会员" /></a>'
							  + '<div class="meta">'
							  + 	'<span style="font-size:11px;color:#F29030;">您的'+memberLevel+'于'+obj.endTime+'到期</span><br>'
							  + 	'<a class="renew" href="javascript:;" onclick="openOrRenewMember('+memberCode+');">续费</a>'
							  + '</div>';
					break;
				case "02":
					memberStr = '<a href="/static/member/hjhy/index.html"" style="margin-left: 4px;"><img src="/images/hj_icon.png" alt="黄橘会员" /></a>'
						  + '<div class="meta">'
						  + 	'<span style="font-size:11px;color:#F29030;">您的'+memberLevel+'于'+obj.endTime+'已到期！</span><br>'
						  + 	'<a class="renew" href="javascript:;" onclick="openOrRenewMember('+memberCode+');">续费</a>'
						  + '</div>';
					break;
				default:
					memberStr = '<div class="meta"><a href="javascript:;" onclick="openOrRenewMember('+memberCode+');" style="font-size:12px;color:#F29030;">开通会员，名师课程免费看</a><br></div>';
					break;
				}
				var str1 = '<div id="user-box"><a href="javascript:;" onclick="personalCenter('+"'"+indexRoute+"'"+')" class="touxiang"><img src="'+obj.userImg+'" class="touxiang" ></a><div class="g-user-card" ><div class="card-inner">';
				var str2 = '<div class="card-top"><a href="javascript:;" onclick="personalCenter('+"'"+indexRoute+"'"+')"><img src="'+obj.userImg+'" class="touxiang"></a><div class="card-top-right-box"><a  href="javascript:;" onclick="personalCenter('+"'"+indexRoute+"'"+')"><span class="name">'+obj.nickname+'</span></a>'+memberStr+'</div>';
				var str3 = '<div class="user-center-box"><ul><li class="course"><a href="javascript:;" onclick="personalCenter('+"'"+courseRoute+"'"+')"><span class="iconfont icon-my-course"></span>我的课程</a></li><li class="order"><a href="javascript:;" onclick="personalCenter('+"'"+orderRoute+"'"+')"><span class="iconfont icon-my-order"></span>订单中心</a></li><li class="favorite"><a href="javascript:;" onclick="personalCenter('+"'"+favoriteRoute+"'"+')"><span class="iconfont icon-my-favorite"></span>我的收藏</a></li><li class="set"><a href="javascript:;" onclick="personalCenter('+"'"+indexRoute+"'"+')"><span class="iconfont icon-personal-set"></span>个人中心</a></li></ul></div>';
				var str4 = '';
				if(courseId === undefined || courseId === '') {
					str4 = '<div style="min-height: 366px;text-align: center;"><p style="margin-top: 30px;">您还没有学习任何课程噢~~</p></div>';
				}else{
					str4 = '<dl>'
						+	'<dt><span class="iconfont icon-shijian" style="font-size:14px;">'+obj.courseTitle+'</span><br></dt>'
						+ 	'<dd>'
						+		'<span class="media-name text-ellipsis" style="padding-left:15px;">'+obj.sectionName+'</span><i class="icon-clock"></i>'
						+		'<a href="/course/play/'+obj.courseId+'" class="continue" title="">继续</a>'
						+	'</dd>'
						+'</dl>';
				}
				var str5 = '<div class="card-history"><span class="history-item">'+str4+'</span></div>'
				var str6 = '<div class="card-sets clearfix"><a href="/logout" class="logout-btn">安全退出</a></div></div></div></div>';
				var str = str1 + str2 + str3 + str5 + str6;
				if(state === 1){
					$("#loginBtn").remove();
					$("#logoutBtn").remove();
					$("#search-box").after(str);
					return;
				}
				$("#user-box").html(str);
				return;
			}
			var loginClass = '.login-model';
			var loginModel = 'login';
			var registerClass = '.register-model';
			var registerModel = 'register';
			var str = '<a href="javascript:;" class="ml-30 mr-30" onclick="defaultLetDivCenter('+"'"+loginClass+"','"+loginModel+"'"+');">'
					+ 	'<i class="login-ico"></i>登录'
					+ '</a>'
					+ '<a href="javascript:;" onclick="defaultLetDivCenter('+"'"+registerClass+"','"+registerModel+"'"+');">'
					+ 	'<i class="regin-ico"></i>注册'
					+ '</a>';
			$("#search-box").after(str);
			return;
		}
	});
}
//清空搜索框
function emptySearchBox(obj) {
	$(obj).val("");
}
//显示和隐藏用户卡片
function showAndHideUserCard() {
	$("#user-box").mouseover (function(){
	    $(".g-user-card").css("display","block");
	});
	$("#user-box").mouseout (function(){
		$(".g-user-card").css("display","none");
	}); 
}

//迷你资讯导航切换
function switchMiniNav() {
	$("#playimages").show();
	$(".nav li").click(function(){
		var z = $(this).index();
		$(this).addClass("current").siblings().removeClass("current");
		$(".main-containner").eq(z).show().siblings(".main-containner").hide();
	})
}

//在线客服直连
function onlineService(){
	$.ajax({
		type:"POST",
		async:false,
		url:"/user/islogin",
		dataType:"json",
		success:function(data){
			var url = "https://xiaojuzi.shujet.com/online/chat/cnctzxkf/01/5a3f041cd7974d46b53f3f753e0ae336/099b057ba3774f4d9898a847beafb7fe"; 
			if(data.code == "100"){
				url = "https://xiaojuzi.shujet.com/online/chat/cnctzxkf/00/5a3f041cd7974d46b53f3f753e0ae336/099b057ba3774f4d9898a847beafb7fe?uid="+data.object;
			}
			openNewWindow = window.open(url);
		}
	});
}

//判断用户是否是会员
function isMember() {
	var flage = false;
	$.ajax({
		async:false,
		type:"POST",
		url:"/user/ismember",
		dataType:"json",
		success:function(data){
			if(data.code === "100"){
				flage = true;
				return;
			}
			return;
		}
	});
	return flage;
}

//开通或续费黄橘会员（正式版）
function openOrRenewMember(code) {
	if(isLogin()) {
		var inviteCode = getParameterValue("invite_code");
		window.open("/tobuy/member?code="+code+"&inviteCode="+inviteCode);
	}
}
//一元体验黄橘会员弹窗
function unitaryExperience(){  
    if(GetCookie("pop")=="yes"){  
    	letDivHide('.wxxc-model');
    }else{
        SetCookie("pop", "yes");
    	defaultLetDivCenter('.wxxc-model'); // 1元体验黄橘会员
    }  
}  
//写入到Cookie  
function SetCookie(name, value) {  
    var exp = new Date();  
    exp.setTime(exp.getTime() + 10 * 60 * 1000);//过期时间10分钟
    document.cookie = name + "=" + escape(value) + "; domain=caishuib.com; path=/; expires=" + exp.toGMTString();  
}  
//写入到Cookie  
function SetCookieForTime (name, value, time) { 
    if (GetCookie(name) == "" || GetCookie(name) == "null") {
		var exp = new Date();  
		exp.setTime(exp.getTime() + time * 60 * 1000);//过期时间自定义
		document.cookie = name + "=" + escape(value) + "; domain=caishuib.com; path=/; expires=" + exp.toGMTString();  
	}
}  
//获取Cookie的值 
function GetCookie(name){  
    var search = name + "=";  
    var value = "";  
    var offset, end;  
    if(document.cookie.length>0){  
        offset = document.cookie.indexOf(search);  
        if(offset != -1){  
            offset += search.length;  
            end = document.cookie.indexOf(";",offset);  
            if(end == -1){
                end = document.cookie.length;  
            }  
            value = unescape(document.cookie.substring(offset,end));  
        }  
    }  
    return value;  
}
//开通黄橘会员（体验版）
function openExperienceMember(code) {
	if(isLogin() && isUnitaryExperience()) {
		var inviteCode = getParameterValue("invite_code");
		window.open("/tobuy/member?code="+code+"&inviteCode="+inviteCode);
	}
}
//隐藏体验会员
function hideExperienceMember(){
	var memberMark = $("#memberMark").val();
	if (typeof memberMark === "undefined" || memberMark === "00") {
		$("#yyty-box").html('<a href="/ads/hjhyNew.htm" target="_blank"><img alt="一元体验" src="/images/yyty.png" style="width:250px;margin-right:-20px;" /></a>');
	} else if (memberMark === "01" || memberMark === "02") {
		$("#yyty-box").html('<a href="https://www.wjx.cn/jq/17105513.aspx" target="_blank"><img alt="问卷调查" src="/images/wjdc.png" style="width:250px;margin-right:-20px;" /></a>');
	}
}

//判断用户能否参加一元体验活动
function isUnitaryExperience() {
	var flage = false;
	$.ajax({
		async:false,
		type:"POST",
		url:"/user/unitary/experience",
		dataType:"json",
		success:function(data){
			if(data.code === "101"){
				flage = true;
				return;
			}
			layer.msg(data.mesg, {icon: 1,time: 5000});
			return;
		}
	});
	return flage;
}

//判断用户是否有可用的优惠券
function isAvailableCoupon() {
	$.ajax({
		async:true,
		type:"POST",
		url:"/user/is/available/coupon",
		dataType:"json",
		success:function(data){
			if(data.code === "100"){
				couponUseRemind(); // 优惠券使用提醒
				return;
			}
		}
	});
}

//优惠券使用提醒
function couponUseRemind() {
	defaultLetDivCenter('.coupon-remind-model');
}
//购买课程
function buyCourse(courseId) {
	if(isLogin()) {
		var inviteCode = GetCookie("invite_code");
		window.open("/tobuy/course?courseId="+courseId+"&inviteCode="+inviteCode);
	}
}

//开通或续费黄橘会员
function openYellowOrangeMember(code) {
	if(isLogin()) {
		var inviteCode = GetCookie("invite_code");
		//window.open("/tobuy/member?code="+code+"&inviteCode="+inviteCode);
		if (inviteCode == "" || inviteCode == "null") {
			//window.location.href = "http://www.caishuib.com/api/user/center/quick/login?site_type=01&route_url=detail/member?id="+code;
			window.open("http://www.caishuib.com/api/user/center/quick/login?site_type=01&route_url=detail/member?id="+code);
			//window.open("http://mall.caishuib.com/#/detail/member?id="+code);
		} else {
			//window.location.href = "http://www.caishuib.com/api/user/center/quick/login?site_type=01&&invite_code="+inviteCode+"&route_url=detail/member?id="+code;
			window.open("http://www.caishuib.com/api/user/center/quick/login?site_type=01&invite_code="+inviteCode+"&route_url=detail/member?id="+code);
			//window.open("http://mall.caishuib.com/#/detail/member?id="+code+"&invite_code="+inviteCode);
		}
	}
}

//获取用户会员信息
function getMemberInfo() {
	var result = "";
	$.ajax({
		async:true,
		type:"POST",
		url:"/user/ismember",
		dataType:"json",
		success:function(data){
			if(data.code === "100"){
				result = data.object;
				return;
			}
			return;
		}
	});
	return result;
}

// 企业服务在线客服直连座席
function enterpriseServiceOS(){
	$.ajax({
		type:"POST",
		async:false,
		url:"/user/islogin",
		dataType:"json",
		success:function(data){
			var url = "https://openapi.shujet.com/direct?t=8AAbVWlE";
			if (data.code == "100") {
				url = "https://openapi.shujet.com/direct?t=QZt04DO9&uid="+data.object;
			}
			window.open(url);
		}
	});
}

// 会员服务在线客服直连座席
function memberServiceOS() {
	$.ajax({
		type:"POST",
		async:false,
		url:"/user/islogin",
		dataType:"json",
		success:function(data){
			var url = "https://openapi.shujet.com/direct?t=ZQOGIMGD"
			if(data.code == "100"){
				var uid = data.object;
				url = "https://openapi.shujet.com/direct?t=2bfC9eOI&uid="+uid;
			}
			window.open(url);
		}
	});
}

// 金融服务在线客服直连终端
function financialServiceOS() {
	$.ajax({
		type:"POST",
		async:false,
		url:"/user/islogin",
		dataType:"json",
		success:function(data){
			var url = "https://openapi.shujet.com/direct?t=qNEc4TBA"
			if(data.code == "100"){
				var uid = data.object;
				url = "https://openapi.shujet.com/direct?t=U2gjCN98&uid="+uid;
			}
			window.open(url);
		}
	});
}

//根据参数名获取浏览器参数值
function getParameterValue(name) {
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
 	var r = window.location.search.substr(1).match(reg);
 	if(r != null) {
 		return unescape(r[2]);
 	}
 	return "";
}  

// 自定义弹窗提示
function customPopupPrompt(title,content,icon,time) {
	if(!time){
		time = 350000;
	}
	$("#popup-icon").addClass(icon);
	$("#popup-title").text(title);
	$("#popup-content").text(content);
	$('.custom-mask').addClass('custom-show');
	$('.custom-mesg-box').addClass('custom-show');
		setTimeout(function()  { 
        $('.custom-mesg-box').removeClass('custom-show');
        $('.custom-mask').removeClass('custom-show');
	},time)
}

// 免登录到官网
function freeLoginToWeb(redirect_url){
	$.ajax({
		type:"POST",
		async:false,
		url:"/user/islogin",
		dataType:"json",
		success:function(data){
			if (data.code == "100") {
				var login_url = "http://mall-beat.4008990000.net/member/externalUserLogin.htm";
				var url = login_url+"?uid="+data.object+"&redirect_url="+redirect_url;
				window.open(url);
			} else {
				letDivCenter('.login-model');
				return;
			}
		}
	});
}

function wechatLogin() {
	var url = window.location.href;
	window.open("/weixin/scan/code/login?url="+url);
}

//个人中心
function personalCenter(url) {
	window.open("/api/user/center/quick/login?route_url="+url);
}

//免登录到个人中心
function freeLoginToHome(route_url) {
	window.open("http://www.caishuib.com/api/user/center/quick/login?site_type=00&route_url="+route_url );
}

//免登录到商城
function freeLoginToMall(route_url) {
	window.open("http://www.caishuib.com/api/user/center/quick/login?site_type=01&route_url="+route_url);
}

//window.location.href = "http://www.caishuib.com/api/user/center/quick/login?site_type=01&route_url=detail/activity?id=b938c7396aeb47a4bbc969013ed7b822";

//缓存邀请码 
function cacheInviteCode () { 
	if (GetCookie("invite_code") != "") {
		return;
	}
    var inviteCode = getParameterValue("invite_code");
	if (inviteCode) {
		SetCookieForTime ("invite_code",inviteCode,1440);
	}
}  
//打开指定的url，并携带邀请码
function openWindowToUrl(url) {
	var inviteCode = GetCookie("invite_code");
	if (inviteCode) {
		if (url.indexOf("?") > -1) {
			window.open(url+"&invite_code="+inviteCode );
		} else {
			window.open(url+"?invite_code="+inviteCode );	
		}
	} else {
		window.open(url);
	}
}  
